sprintf/snprintf replacements (#548)
authortsteven4 <13596209+tsteven4@users.noreply.github.com>
Tue, 28 Apr 2020 12:46:14 +0000 (06:46 -0600)
committerGitHub <noreply@github.com>
Tue, 28 Apr 2020 12:46:14 +0000 (06:46 -0600)
* fix g++ 9.3 warnings about snprintf.

These appear at -O2.

* handle garmin category conversion similar to garmin_fs.cc

* fix stmwpp includes under configure.

garmin_fit.cc
garmin_fs.cc
garmin_txt.cc
netstumbler.cc
stmwpp.cc

index a50c24c5fed869eef0fa16454d461360c25e7e0c..32ccb3f79a1ab06438ced0f6f4745d4ad61fb656 100644 (file)
@@ -362,11 +362,11 @@ GarminFitFormat::fit_parse_data(const fit_message_def& def, int time_offset)
   uint8_t cadence = 0xff;
   uint16_t power = 0xffff;
   int8_t temperature = 0x7f;
-  int32_t startlat = 0x7fffffff;
-  int32_t startlon = 0x7fffffff;
+  //int32_t startlat = 0x7fffffff;
+  //int32_t startlon = 0x7fffffff;
   int32_t endlat = 0x7fffffff;
   int32_t endlon = 0x7fffffff;
-  uint32_t starttime = 0; // ??? default ?
+  //uint32_t starttime = 0; // ??? default ?
   uint8_t event = 0xff;
   uint8_t eventtype = 0xff;
 
@@ -500,19 +500,19 @@ GarminFitFormat::fit_parse_data(const fit_message_def& def, int time_offset)
           if (global_opts.debug_level >= 7) {
             debug_print(7,"%s: parsing fit data: starttime=%d\n", MYNAME, val);
           }
-          starttime = val;
+          //starttime = val;
           break;
         case kFieldStartLatitude:
           if (global_opts.debug_level >= 7) {
             debug_print(7,"%s: parsing fit data: startlat=%d\n", MYNAME, val);
           }
-          startlat = val;
+          //startlat = val;
           break;
         case kFieldStartLongitude:
           if (global_opts.debug_level >= 7) {
             debug_print(7,"%s: parsing fit data: startlon=%d\n", MYNAME, val);
           }
-          startlon = val;
+          //startlon = val;
           break;
         case kFieldEndLatitude:
           if (global_opts.debug_level >= 7) {
@@ -587,9 +587,7 @@ GarminFitFormat::fit_parse_data(const fit_message_def& def, int time_offset)
     auto* lappt = new Waypoint;
     lappt->latitude = GPS_Math_Semi_To_Deg(endlat);
     lappt->longitude = GPS_Math_Semi_To_Deg(endlon);
-    char cbuf[10];
-    snprintf(cbuf, sizeof(cbuf), "LAP%03d", ++lap_ct);
-    lappt->shortname = cbuf;
+    lappt->shortname = QString("LAP%1").arg(++lap_ct, 3, 10, QLatin1Char('0'));
     waypt_add(lappt);
   }
   break;
index 232d7f339aa227cfe0d91f0542d1ee49f4dce530..9c824597047dd64e85a444850efb3e95c2e5325f 100644 (file)
@@ -285,12 +285,7 @@ garmin_fs_convert_category(const char* category_name, uint16_t* category)
   } else if (global_opts.inifile != nullptr) {
     // Do we have a gpsbabel.ini that maps category names to category #'s?
     for (i = 0; i < 16; i++) {
-      char key[3];
-
-      // use assertion to silence gcc 7.3 warning
-      // warning: ā€˜%d’ directive output may be truncated writing between 1 and 11 bytes into a region of size 3 [-Wformat-truncation=]
-      assert((i>=0) && (i<16));
-      snprintf(key, sizeof(key), "%d", i + 1);
+      QString key = QString::number(i + 1);
       QString c = inifile_readstr(global_opts.inifile, GMSD_SECTION_CATEGORIES, key);
       if (c.compare(category_name, Qt::CaseInsensitive) == 0) {
         cat = (1 << i);
index 03b83a643416afed879d42fd49aa260363420356..87f59ed135ce4764dd0eb6824e58821138a32230 100644 (file)
@@ -408,8 +408,7 @@ print_categories(uint16_t categories)
     if ((categories & 1) != 0) {
       QString c;
       if (global_opts.inifile != nullptr) {
-        char key[3];
-        snprintf(key, sizeof(key), "%d", i + 1);
+        QString key = QString::number(i + 1);
         c = inifile_readstr(global_opts.inifile, GMSD_SECTION_CATEGORIES, key);
       }
 
index 761a480ad9974c4b2e0e1deb930101590d1e0f60..3ab3d9269d2c33a531dc3c5b2e0c277008d6a26a 100644 (file)
@@ -90,7 +90,7 @@ data_read()
   char* ibuf;
   char ssid[2 + 32 + 2 + 1];                   /* "( " + SSID + " )" + null */
   char mac[2 + 17 + 2 + 1];                    /* "( " + MAC + " )" + null */
-  char desc[sizeof ssid - 1 + 15 + 1]; /* room for channel/speed */
+  QString desc;
   double lat = 0, lon = 0;
   int line_no = 0;
   int stealth_num = 0, whitespace_num = 0;
@@ -240,10 +240,10 @@ data_read()
     }
 
     if (snmac) {
-      snprintf(desc, sizeof desc, "%s/%d Mbps/Ch %d", ssid, speed, channel);
+      desc = QString("%1/%2 Mbps/Ch %3").arg(ssid).arg(speed).arg(channel);
       wpt_tmp->shortname = (mac);
     } else {
-      snprintf(desc, sizeof desc, "%d Mbps/Ch %d/%s", speed, channel, mac);
+      desc = QString("%1 Mbps/Ch %2/%3").arg(speed).arg(channel).arg(mac);
       wpt_tmp->shortname = (ssid);
     }
 
index a147cf1bc21d2f8fe4a1f323412d708eedccc053..f74cbdf738f421e4c37ab9872a6436653f197932 100644 (file)
--- a/stmwpp.cc
+++ b/stmwpp.cc
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */
 
+#include <cstdio>                  // for sscanf, snprintf
+#include <cstdlib>                 // for atof, atoi
+#include <cstring>                 // for memset
+#include <ctime>                   // for tm
+
+#include <QtCore/QDateTime>        // for QDateTime
+#include <QtCore/QString>          // for QString
+#include <QtCore/QTime>            // for QTime
+#include <QtCore/QVector>          // for QVector
 
 #include "defs.h"
+#include "cet_util.h"              // for cet_convert_init
+#include "csv_util.h"              // for csv_lineparse
+#include "gbfile.h"                // for gbfprintf, gbfclose, gbfgetstr, gbfopen, gbfile, gbfputs
+#include "src/core/datetime.h"     // for DateTime
 
-#if CSVFMTS_ENABLED
 
-#include "csv_util.h"
-#include "cet_util.h"
-#include <cctype>
-#include <cstdio>
-#include <cstdlib>
+#if CSVFMTS_ENABLED
 
 static gbfile* fin, *fout;
 static route_head* track, *route;
@@ -229,20 +237,10 @@ stmwpp_write_double(const double val)
 static void
 stmwpp_waypt_cb(const Waypoint* wpt)
 {
-  char cdate[16], ctime[16];
-
   if (track_index != track_num) {
     return;
   }
 
-  const time_t tt = wpt->GetCreationTime().toTime_t();
-  struct tm tm = *gmtime(&tt);
-  tm.tm_year += 1900;
-  tm.tm_mon++;
-
-  snprintf(cdate, sizeof(cdate), "%02d/%02d/%04d", tm.tm_mon, tm.tm_mday, tm.tm_year);
-  snprintf(ctime, sizeof(ctime), "%02d:%02d:%02d", tm.tm_hour, tm.tm_min, tm.tm_sec);
-
   QString sn;
   switch (what) {
 
@@ -262,7 +260,8 @@ stmwpp_waypt_cb(const Waypoint* wpt)
   }
   stmwpp_write_double(wpt->latitude);
   stmwpp_write_double(wpt->longitude);
-  gbfprintf(fout, "%s,%s", cdate, ctime);
+  QString datetime = wpt->GetCreationTime().toUTC().toString("MM/dd/yyyy,HH:mm:ss");
+  gbfputs(datetime, fout);
   switch (what) {
   case STM_WAYPT:
   case STM_RTEPT: